package com.hospital.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;

@WebServlet("/manage/CheckInfoServlet")
public class CheckInfoServlet extends HttpServlet {
	//检查项目信息Servlet
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String method = request.getParameter("method");
		if ("add".equals(method)) {
			String name = request.getParameter("name").trim();
			String pricestr = request.getParameter("price").trim();
			Double price = Double.parseDouble(pricestr);
			String description = request.getParameter("description");
			String sql = "insert into t_checklist(name , price , description) values('" + name +"', '" + price + "' , '" + description +"')";
			DbUtil.add_modify(sql);
		} else if ("del".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.deldeptId("t_checklist", id);
		} else if ("modify".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String pricestr = request.getParameter("price").trim();
			Double price = Double.parseDouble(pricestr);
			String description = request.getParameter("description");
			String sql = "update t_checklist set price = '" + price + "'"+ " , description= '"+description + "' where id = " + id;
			DbUtil.add_modify(sql);
		}
		request.getRequestDispatcher("/manage/check_info_manage.jsp").forward(request, response);
	}
}
